using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace MapaMovil
{
    class DrawableArrow
    {
        ArrowPoint[] points;
        System.Drawing.Brush brush;
        System.Drawing.Pen pen;

        int height;
        int x, y;

        public DrawableArrow(double h, double l, double th, double tl, System.Drawing.Brush b, System.Drawing.Pen p)
        {
            points = new ArrowPoint[7];

            points[0] = new ArrowPoint(h, -Math.PI / 2.0);

            points[1] = new ArrowPoint(Math.Sqrt(h * h + l * l), -Math.Atan(h / l));

            points[2] = new ArrowPoint(Math.Sqrt((h + th) * (h + th) + l * l), -Math.Atan((h + th) / l));

            points[3] = new ArrowPoint(l + tl, 0);

            points[4] = new ArrowPoint(Math.Sqrt((h + th) * (h + th) + l * l), Math.Atan((h + th) / l));

            points[5] = new ArrowPoint(Math.Sqrt(h * h + l * l), Math.Atan(h / l));

            points[6] = new ArrowPoint(h, Math.PI / 2.0);

            brush = b;
            pen = p;

            height = (int)Math.Ceiling(2 * h);
            x = y = 0;

        }

        public void setRotationAngle(double rotAngle) 
        {
            for (int i = 0; i < points.Length; ++i)
                points[i].setAngle(rotAngle);
        }

        public void setPosition(double x, double y)
        {
            for (int i = 0; i < points.Length; ++i)
                points[i].setPosition(x, y);
            this.x = (int)Math.Round(x);
            this.y = (int)Math.Round(y);
        }

        public void draw(System.Drawing.Graphics g)
        {
            System.Drawing.Point[] drawingPoints = new System.Drawing.Point[points.Length];
            for (int i = 0; i < points.Length; ++i)
                drawingPoints[i] = points[i].getPoint();
            
            g.FillPolygon(brush, drawingPoints);
            g.DrawPolygon(pen, drawingPoints);
            g.FillEllipse(brush, x - height/2, y - height/2, height, height);

        }
    }
}
